package com.kunbo.cn.entity.system;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.JoinColumn; 

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;

@Entity
@Table(name="sys_role")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
@EntityListeners(AuditingEntityListener.class)
@Data
public class SysRole implements Serializable{
	/** serialVersionUID*/
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
	private String id;//主键uuid
	
	private String role; // 角色标识程序中判断使用,如"admin",这个是唯一的:  
    private String description; // 角色描述,UI界面显示使用  
    private Boolean available = Boolean.FALSE; // 是否可用,如果不可用将不会添加给用户  
  
    // 角色 -- 权限关系：多对多关系;  
    @ManyToMany(fetch = FetchType.EAGER)  
    @JoinTable(name = "SysRolePermission", joinColumns = { @JoinColumn(name = "roleId") }, inverseJoinColumns = {  
            @JoinColumn(name = "permissionId") })  
    private List<SysPermission> permissions;  
  
    // 用户 - 角色关系定义;  
    @ManyToMany  
    @JoinTable(name = "SysUserRole", joinColumns = { @JoinColumn(name = "roleId") }, inverseJoinColumns = {  
            @JoinColumn(name = "userId") })  
    private List<UserInfo> userInfos;// 一个角色对应多个用户  
    
    @CreatedDate
    private Date createTime;//创建时间
    @LastModifiedDate
    private Date lastModifiedTime;//修改时间

}
